<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Referee;
use App\Models\Dealer;
use Illuminate\Support\Carbon;
use Faker\Generator;

class RefereeSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // 防止内存耗尽的异常
        ini_set('memory_limit', -1);

        $now = Carbon::now();
        $dealer_ids = Dealer::all()->pluck('id')->toArray();
        // 获取 Faker 实例
        $faker = app(Generator::class);

        $rows = Referee::factory()->times(10)->make()->each(function ($row, $index) use ($now, $faker, $dealer_ids) {
            $row->dealer_id = $faker->randomElement($dealer_ids);
            $row->created_at = $now;
            $row->updated_at = $now;
        });
        Referee::insert($rows->toArray());
        print("插入完成 \n");
    }
}
